'use strict';
// app/service/user.js
const Service = require('egg').Service;

class ProjectService extends Service {
  async find(current = 1, size = 10) {
    const site = this.app.mysql.get('site');
    this.logger.info('接入参数：', current, size);
    try {
      const project = await site.query('SELECT * FROM project LIMIT ?,?', [
        (current - 1) * size,
        size || 10,
      ]);
      const count = await site.query('SELECT COUNT(id) AS count FROM project');
      return {
        list: project,
        current: current || 1,
        size: size || 10,
        sizes: Math.ceil(count[0].count / size),
        total: count[0].count,
      };
    } catch (error) {
      this.logger.error(error);
    }
  }
}

module.exports = ProjectService;
